<div class="modal-content">

    <div class="modal-body clearfix">
        <div class="row">
            {# 用户简介 #}
            <div class="col-md-12">
                <div class="col-md-9">
                    <div class="col-md-12">
                        <div class=col-md-4>
                            <input type="text" class="form-control hidden" id="userId" value="{{ result['id'] }}">
                            <input type="text" class="form-control" id="userNickname" value="{{ result['nickname'] }}" readonly="readonly">
                        </div>
                        <div class=col-md-4>
                            <div class=col-md-6>
                                <div class="radio">
                                    <input type="radio" name="userGender" id="userGender1" value="1" {% if result['gender']==1 %} checked {% endif %}>
                                    先生
                                </div>
                            </div>
                            <div class=col-md-6>
                                <div class="radio">
                                    <input type="radio" name="userGender" id="userGender2" value="0" {% if result['gender']==0 %} checked {% endif %}>
                                    女士
                                </div>
                            </div>
                        </div>
                        <div class=col-md-4>
                            <label style="color: orange;">今日已外呼次数: {{ result['call_times'] }}</label>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class=col-md-4>
                            <input type="text" class="form-control" id="userRealMobile" value="{{ result['mobile'] }}" readonly="readonly">
                            <input type="hidden" class="form-control" id="user-full-mobile" value="{{ result['full_mobile'] }}">
                        </div>
                        <div class=col-md-3>
                            {{ result['type_display'] }}
                        </div>
                        <div class=col-md-3>
                            {{ result['address'] }}
                        </div>
                    </div>
                     <div class="col-md-12">
                         <div class=col-md-10 style="color: blue">
                        发起方式(手动外呼会显示为呼入): {{ result['call_type'] }}
                         </div>
                    </div>
                </div>
            </div>

            <br/><br/><br/><br/>
            <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

            {# 项目信息 #}
            <div class="col-md-12">
                <table class="table table-bordered table-hover table-condensed table-striped">
                    <thead>
                        <tr>
                            <th>发布时间</th>
                            <th>订单类型</th>
                            <th>处理时长</th>
                            <th>录音</th>
                            <th>处理人</th>
                        </tr>
                    </thead>
                    <tbody>
                    {% for i in result['demands'] %}
                        <tr>
                            <td style="color: orangered; font-weight: bold;">{{ i['published_datetime'] }}</td>
                            <td style="color: orangered; font-weight: bold;">{{ i['cate_display'] }}</td>
                            <td>{{ i['handle_time'] }}</td>
                            <td>
                                <audio src="{{ i['demand_audio']|safe }}" controls="controls" controlsList="nodownload">
                                    您的浏览器无法播放该音频。
                                </audio>
                            </td>
                            <td>{{ i['admin_nickname'] }}</td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="modal-footer">
        <div class="col-md-3">
            <button class="btn btn-success btn-block" data-dismiss="modal" aria-label="Close" id="create_demand" disabled>创建订单</button>
        </div>
        <div class="col-md-3">
            <button class="btn btn-danger btn-block" data-dismiss="modal" aria-label="Close" id="not_create_demand" disabled>不予创建</button>
        </div>
        <div class="col-md-3">
            <button class="btn btn-warning btn-block" data-dismiss="modal" aria-label="Close" id="wait_for_reject" disabled>未接通, 等待自动回呼</button>
        </div>
        <div class="col-md-3">
            <button class="btn btn-default btn-block" data-dismiss="modal" aria-label="Close" id="delay_handle" disabled>延后处理</button>
        </div>
    </div>

</div>

<script type="text/javascript">
    // 创建订单触发事件
    function create_demand_event() {
        show_demand_type_modal();
    }
    $('#create_demand').click(function (){
        create_demand_event();
    });

    // 不予创建按钮触发事件
    function set_agent_idel() {
        init_global_variable();
        phone.setBusy(false, 0);
        console.log('点击了不予创建按钮');
    }
    $('#not_create_demand').click(function () {
        $('#not-create-modal').modal({backdrop: "static", keyboard: false});
    });
    $('#not_create_goto_customer_modal').click(function (){
        show_customer_modal();
    });
    $('#not_create_confirm').click(function (){
        if ($('input[name=not_create_reason]:checked').val() === '自定义' && $('#not_create_text').val() == ''){
            alert('自定义原因不能为空!');
            return false;
        }
        $.ajax({
            type: "POST",
            contentType: "application/json",
            url: "{{ url_for('sever_moor_bp.ajax_not_create_demand') }}",
            data: JSON.stringify({
                // 'uid': user_intro.id,
                'uid': $('#userId').val(),
                'not_create_reason': $('input[name=not_create_reason]:checked').val(),
                'not_create_text': $('#not_create_text').val()
            })
        });
        set_agent_idel();
        alert('操作成功');
        $('.inp1').val("");
{#        getRecords();#}
{#        location.reload();#}
    });
    $('input[name=not_create_reason]').change(function(){
        var val = $(this).val();
        if (val === '自定义'){
            $('#not_create_text').show();
        }else{
            $('#not_create_text').hide()
        }
    });

    // 用户拒接
    $('#wait_for_reject').click(function () {
        var flag = confirm('请确认操作?');
        if (flag === false){
            return false;
        }
        $.ajax({
            type: "POST",
            contentType: "application/json",
            url: "{{ url_for('sever_moor_bp.ajax_waiting_for_reject') }}",
            data: JSON.stringify({
                'uid': user_intro.id
            })
        });
        set_agent_idel();
        alert('操作成功');
        $('.inp1').val("");
{#        getRecords();#}
{#        location.reload();#}
    });

    // 延后处理按钮触发事件
    function delay_handle_event() {
        $.ajax({
            type: "POST",
            contentType: "application/json",
            url: "{{ url_for('sever_moor_bp.ajax_demand_handle_delay') }}",
            data: JSON.stringify({
                'uid': user_intro.id,
                'mobile': user_intro.mobile,
                'type': $('input[name=delay_type]:checked').val(),
                'delay_date': $('#delay_date').val(),
                'delay_reason': $('#delay_reason').val()
            })
        });
        init_global_variable();
        phone.setBusy(false, 0);
        console.log('点击了延后处理按钮');
        $('.inp1').val("");
{#        getRecords();#}
{#        location.reload()#}
    }
    $('#delay_handle').click(function () {
        $('#delay-handle-modal').modal({backdrop: "static", keyboard: false});
    });
    $('#delay_handle_goto_customer_modal').click(function (){
        show_customer_modal();
    });
    $('#delay_handle_confirm').click(function (){
        if ($('input[name=delay_type]:checked').val() == '4' && $('#delay_date').val() == ''){
            alert('自定义日期不能为空!');
            return false;
        }
        delay_handle_event();
    });
    $('input[name=delay_type]').change(function(){
        var val = $(this).val();
        if (val == 4){
            $('#delay_date').show();
        }else{
            $('#delay_date').hide()
        }
    })
</script>


